package cn.icatw.admin.utils;

import org.springframework.stereotype.Component;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author icatw
 * @date 2022/10/15
 * @email 762188827@qq.com
 * @apiNote
 */
@Component
public class ImageUtil {
    public String getImageSize(String imageUrl) throws IOException {
        URL url = new URL(imageUrl);
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        BufferedImage image = ImageIO.read(connection.getInputStream());
        int srcWidth = image.getWidth();      // 源图宽度
        int srcHeight = image.getHeight();    // 源图高度

        System.out.println("srcWidth = " + srcWidth);
        System.out.println("srcHeight = " + srcHeight);
        return srcWidth+"*"+srcHeight;
    }
}
